import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes = [

  {
	  path:'/',
	  name:'login',
	  component:()=>import('../views/Login.vue')
  },
  {
	  path:'/index',
	  name:'index',
	  component:()=>import('../components/Index.vue'),
	  children:[
		  //写邮件路由
		  {
			  path:'/write',
			  name:'write',
			  component:()=>import('../components/Email/Write.vue')
		  },
		  //收件箱路由
		  {
		  			  path:'/inbox',
		  			  name:'inbox',
		  			  component:()=>import('../components/Email/InBox.vue')
		  },
		  //草稿箱路由
		  {
			  path:'/draft',
			  name:'draft',
			  component:()=>import('../components/Email/Draft.vue')
		  },
		  //星标邮件路由
		  {
			  path:'/sign',
			  name:'sign',
			  component:()=>import('../components/Email/Sign.vue')
		  },
		  //已删除的路由
		  {
			  path:'/delete',
			  name:"delete",
			  component:()=>import('../components/Email/Delete.vue')
		  },
		  //通讯录路由
		  {
			  path:'/contact',
			  name:'contact',
			  component:()=>import('../components/Contact/Contact.vue')
		  },
		  //编辑通知公告路由
		  {
		  			  path:'/editnotice',
		  			  name:'editnotice',
		  			  component:()=>import('../components/Notice/EditNotice.vue')
		  },
		  //论坛会议路由
		  {
			  path:'/meeting',
			  name:'meeting',
			  component:()=>import('../components/Meeting/Meeting.vue')
		  },
		  //编辑通知公告路由
		  {
			  path:'/editnotice',
			  name:'editnotice',
			  component:()=>import('../components/Notice/EditNotice.vue')
		  },
		  //查看通知公告路由
		  {
			  path:'/managenotice',
			  name:'managenotice',
			  component:()=>import('../components/Notice/ManageNotice.vue')
		  },
		  {
			  path:'/listnotice',
			  name:'listnotice',
			  component:()=>import('../components/Notice/ListNotice.vue')
		  }
		  
	  ]
  },
  {
  	  path:'/aside',
  	  name:'aside',
  	  component:()=>import('../views/Aside.vue')
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})


router.beforeEach((to,from,next)=>{
	
	//配置守卫路由集合
	const routList=['/index']
	let user=JSON.parse(sessionStorage.getItem("user"))
	
	//判断to 转入的路由是不是涉及到 守卫路由集合
	if(routList.indexOf(to.path)>=0){
		if(user==null||user==''){
			//没登陆控制路由的跳转到登录路由中去
			
			router.push('/')
			//location.reload()
		}
	}	
	next()
	
})



export default router
